//
//  fUjinXiangJingTableViewCell.m
//  GOGOTravel
//
//  Created by dllo on 16/3/5.
//  Copyright © 2016年 果果. All rights reserved.
//

#import "fUjinXiangJingTableViewCell.h"
#import "FuJinXiangQingCollectionViewCell.h"

@interface fUjinXiangJingTableViewCell ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) BaseCollectionView *collection;

@end

@implementation fUjinXiangJingTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createCollection];
        
    }
    return self;
}

- (void)setArr:(NSArray *)arr{
    if (_arr != arr) {
        [_arr release];
        _arr = [arr retain];
    }
    
        
        [_collection reloadData];
   
    
}

- (void)createCollection{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 220);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    
    self.collection = [[BaseCollectionView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 220) collectionViewLayout:layout];
    _collection.delegate = self;
    _collection.dataSource = self;
    _collection.backgroundColor = [UIColor blackColor];
    _collection.pagingEnabled = YES;
    [self.contentView addSubview:_collection];
    
    [_collection release];
    
    [_collection registerClass:[FuJinXiangQingCollectionViewCell class] forCellWithReuseIdentifier:@"FuJinXiangQingCollectionViewCell"];
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _arr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    FuJinXiangQingCollectionViewCell *Cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FuJinXiangQingCollectionViewCell" forIndexPath:indexPath];
    Cell.backgroundColor = [UIColor blackColor];
    NSString *str = _arr[indexPath.row];
   
    [Cell.imageView1 sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:PLACE_HLODER]];
   
    
    
    return Cell;
}

- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{
    
    [UIView animateWithDuration:0.5 animations:^{
        cell.layer.transform = CATransform3DMakeScale(1.5, 1.5, 0);
        cell.layer.transform = CATransform3DMakeScale(1, 1, 1);
    } completion:^(BOOL finished) {
        
    }];
    
    
}




- (void)dealloc{
    [_arr release];
    [_collection release];
    [super dealloc];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
